﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors.Repository;
using DevTeam;

using System;
using System.Data;

namespace ConfExpert.Forms.SatinAlma.YeniYapi
{
    public partial class Konf : XForm
    {
        public Konf()
        {
            InitializeComponent();
        }

        private void Konf_Load(object sender, EventArgs e)
        {
            gridView1.Init("GetKonf2", 0);
            gridView1.AddColumn("GelenYuzde", typeof(decimal), "100*GelenQty/QtyOrdered");
            gridView1.AddColumn("Qty", typeof(decimal));

            gridView1.FormatAsNumber(1, "KonfMt", "QtyOrdered", "GelenQty", "Qty", "GelenYuzde");
            gridView1.AddSummary("KonfMt", "QtyOrdered", "GelenQty", "Qty");
            //gridView1.FormatAsPercentage("GelenYuzde");
            gridView1.MakeColumnInvisible("KonfId", "AyrimlarId", "EklenmeTarihi", "UserId");
            gridView1.YanYanaGetirSoluna("GomlekTermini", "Qty", "KonfMt", "Fiyat", "CurrencyId", "OngShipMethodId", "RevShipMethodId", "OngShipDate", "RevShipDate", "GelenQty", "GelenYuzde");
            gridView1.BestFitColumns();

            DataTable dtx = ExecuteDataTable("GetKonfVendors");
            RepositoryItemGridLookUpEdit gle = GetCustomGLE(dtx, "Name", "VendorId");

            gleUretici.Edit.Assign(gle);
            ((RepositoryItemGridLookUpEdit)gleUretici.Edit).TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            gleUretici.EditValueChanged += gleUretici_EditValueChanged;

            if (isKD)
            {
                gridView1.MakeReadOnly("KonfirmasyonNo", "KonfirmasyonTarihi", "CurrencyId", "PaymentTermId", "PaymentMethodId", "TeslimSekliId", "KonfMt", "Fiyat", "Degisim", "MasrafKalemiId", "OngShipMethodId", "RevShipMethodId", "OngShipDate", "RevShipDate", "CarrierId");
                btnKaydet.Enabled = true;
            }
            else
                gridView1.MakeReadOnly();

            btnKaydet.ItemClick += btnKaydet_ItemClick;
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();
            gridView1.Update("KonfId,KonfirmasyonNo,KonfirmasyonTarihi,CurrencyId,PaymentTermId,PaymentMethodId,TeslimSekliId,KonfMt,Fiyat,Degisim,MasrafKalemiId,OngShipMethodId,RevShipMethodId,OngShipDate,RevShipDate,CarrierId", "Konf");
            Notify("Kaydedildi.");
        }

        void gleUretici_EditValueChanged(object sender, EventArgs e)
        {
            int UreticiId = gleUretici.EditValue.ToInt();

            gridView1.RefreshDataSource("GetKonf2", UreticiId);
            gridView1.BestFitColumns();
        }
    }
}
